<?php

namespace App\Http\Controllers\Admin\Setting;

use App\Http\Controllers\Controller;
use App\Models\Cities;
use Illuminate\Http\Request;

class CitiesController extends Controller
{
    protected $suffix = '';
    protected $page_title = 'CITY';
    protected $page_name = 'cities';
    protected $view_index = 'admin.setting.cities.index';
    protected $view_show = 'admin.setting.cities.show';
    protected $view_edit = 'admin.setting.cities.edit';
    protected $view_create = 'admin.setting.cities.create';
    protected $index_link = '/admin/setting/cities/';

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $page = [
            'page_name' => $this->page_name,
            'title' => ts($this->page_title) . $this->suffix
        ];
        $label = $request->input('label');
        $value = $request->input('value');
        $model = new Cities();
        if (!empty($value)) {
            if ($label == 1) {
                $model = $model->where('english_value', 'like', '%'.$value.'%');
            } elseif ($label == 2) {
                $model = $model->where('traditional_chiness_value', 'like', '%'.$value.'%');
            } elseif ($label == 2) {
                $model = $model->where('simplified_chiness_value', 'like', '%'.$value.'%');
            } else {
                $model = $model->orWhere('english_value', 'like', '%'.$value.'%')
                    ->orWhere('traditional_chiness_value', 'like', '%'.$value.'%')
                    ->orWhere('simplified_chiness_value', 'like', '%'.$value.'%');
            }
        }
        $data = $model->orderBy('id')->paginate();
        return view($this->view_index, [
            'data'=>$data,
            'page' => $page,
        ]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        return [$id];

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Request $request, $id)
    {
        $data = Cities::findOrFail($id);
        return view($this->view_edit, ['data'=>$data]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        return [$id];
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
